package cn.jsj.dispose;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.jsj.bgtodb.PayPlanProperty;
/**
 * 案件登记处理类
 * @author LI
 *
 */
public class RegisterCaseInfo extends javax.servlet.http.HttpServlet implements javax.servlet.Servlet {
	 public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// 调试信息
		 cn.jsj.utils.SysLogger.PrintInfo("案件登记处理类！！！");

		//输出流
			java.io.PrintWriter out=response.getWriter();

		 //新建案件信息类
		 cn.jsj.pojo.TblCaseInfo tci=new cn.jsj.pojo.TblCaseInfo();
		 	//赋值
			tci.setAffairCause(request.getParameter("raffaircause").trim());
			//卷宗押金收退情况
			tci.setArchiveDeposit(Integer.parseInt(request.getParameter("rarchivedeposit").trim()));
			//票据
			tci.setCaseBill(Integer.parseInt(request.getParameter("rcasebill").trim()));
			//获取委托人
			tci.setCaseConsigner(request.getParameter("rcaseconsigner"));
			//合同金额
			tci.setCaseMoney(Integer.parseInt(request.getParameter("rcasemoney").trim()));
			//付款情况
			tci.setCasePayStatus(request.getParameter("rcasepaystatus").trim());
			//分解付款情况
			String payStaus=request.getParameter("rcasepaystatus").trim();
			System.out.println(payStaus);
			String[] arr=payStaus.split("，");
			if(arr[0].length()>20){
				arr=payStaus.split(",");
			}
			System.out.println(arr.length);
			//计划付款情况队列
			java.util.List<PayPlanProperty> payPlanList=new java.util.LinkedList<PayPlanProperty>();
			//赋值
			for(int i=0;i<arr.length;i++){
				String payplanRecord=arr[i];
				System.out.println(payplanRecord);
				//一条记录|||
				String[] payPlanArr=payplanRecord.split(":");
				if(payPlanArr.length<2){
					payPlanArr=payplanRecord.split("：");
				}
				System.out.println(payPlanArr[0]+"  "+payPlanArr[1]);
				PayPlanProperty ppp=new PayPlanProperty();
				ppp.setPayPlanTime(cn.jsj.utils.TimeDispose.transferDate(payPlanArr[0]));
				ppp.setPayPlanMoney(Integer.parseInt(payPlanArr[1]));
				payPlanList.add(ppp);
			}

			//增加计划付款情况
			cn.jsj.dao.TblCasePayPlanDAO tcppd=new cn.jsj.dao.TblCasePayPlanDAO();
			tcppd.addPayPlanInfo(payPlanList, request.getParameter("rcontractnumber").trim());
			//获得案件类别编号
			tci.setCaseType(Integer.parseInt(request.getParameter("rcasetype").trim()));
			//获得案件性质编号
			tci.setCaseProperty(Integer.parseInt(request.getParameter("rcaseproperty").trim()));
			//采集人提成金额
			tci.setCaser_roy_money(Integer.parseInt(request.getParameter("rcaser_roy_money").trim()));
			//备注
			tci.setCaseRemark(request.getParameter("rcaseremark").trim());
			//签订时间
			tci.setCaseSignTime(cn.jsj.utils.TimeDispose.transferDate(request.getParameter("rcasesigntime").trim()));
			//检查院公函
			tci.setCheckOffLetter(request.getParameter("rcheckoffletter").trim());
			//合同号
			tci.setContractNumber(request.getParameter("rcontractnumber").trim());
			//合同文本
			tci.setContractText(Integer.parseInt(request.getParameter("rcontracttext").trim()));
			//开庭时间
			tci.setCourtDay(cn.jsj.utils.TimeDispose.transferDate(request.getParameter("rcourtday").trim()));
			//法院公函
			tci.setCourtOffLetter(request.getParameter("rcourtoffletter").trim());
			//删除标志
			tci.setDeleteLabel(0);
			//采集人
			tci.setGatherPerson(request.getParameter("rgatherperson").trim());
			//获取委托人身份证号
			tci.setIdentityNumber(request.getParameter("ridentitynumber").trim());
			//会见函
			tci.setInterviewLetter(request.getParameter("rinterviewletter").trim());
			//介绍信
			tci.setIntroLetter(request.getParameter("rintroletter").trim());
			//律师函
			tci.setLawyersLetter(request.getParameter("rlawyersletter").trim());
			//授权委托书
			tci.setLetterAuthor(Integer.parseInt(request.getParameter("rletterauthor").trim()));
			//对方当事人
			tci.setOppositeParty(request.getParameter("roppositeparty").trim());
			//其他文本
			tci.setOtherText(request.getParameter("rothertext").trim());
			//联系方式
			tci.setPhoneNumber(request.getParameter("rphonenumber").trim());
			//结案情况
			tci.setSettleLawsuit(Integer.parseInt(request.getParameter("rsettlelawsuit").trim()));
			//根据律师姓名获得律师id
			cn.jsj.dao.TblLawyerDAO tld=new cn.jsj.dao.TblLawyerDAO();
			int lawyerId=tld.getLawyerId(request.getParameter("rundertakelawyer").trim());
			//如果不存在
			if(lawyerId==0){
				out.println("{message:'承办律师不存在'}");
				return;
			}
			tci.setUndertakeLawyer(lawyerId);

			//获取付款备注情况
			String payStatusBrief=request.getParameter("rcasepaystatusbrief").trim();
			tci.setPayStatusBrief(payStatusBrief);
			//获取承担备注
			String undertakeBrief=request.getParameter("rundertakelawyerbrief").trim();
			tci.setUndertakeBrief(undertakeBrief);

			//调试信息
			cn.jsj.utils.SysLogger.PrintInfo("赋值完成！！！");

			//保存登记后的案件信息
			cn.jsj.dao.TblCaseInfoDAO tcid=new cn.jsj.dao.TblCaseInfoDAO();
			int saveResult=tcid.registerCaseInfo(tci);

			// 调试信息
			cn.jsj.utils.SysLogger.PrintInfo("登记案件信息结果--------------->"+saveResult);


			//如果保存成功
			 if(saveResult==1){
				 out.println("{message:'登记成功'}");
			 }
			 else{
				 out.println("{message:'登记失败'}");
			 }
			 out.flush();
			 out.close();
	}

	 public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		 doPost(request,response);
	 }

}